<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('协助发货管理')" />

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-form-label">订单号</label>
                        <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="ddh" id="ddh" placeholder="请输入订单号" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">装车编号</label>
                        <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="zcdbh" id="zcdbh" placeholder="请输装车编号" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">下发状态</label>
                        <select name="xfzt">
                            <option value="">全部</option>
                            <option value="0">未下发</option>
                            <option value="1">已下发</option>
                            <option value="2">已完成</option>
                            <option value="3">PC端发运</option>
                        </select>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">流水号</label>
                        <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="lsh" id="lsh" placeholder="请输流水号" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">发起人</label>
                        <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="fqr" id="fqr" placeholder="请输发起人" />
                        </div>
                    </div>
                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal search_btn" lay-event="searchEvent" data-type="reload">查询</a>
                    </div>
                    <div class="layui-inline inline-reset-btn">
                        <button type="reset" class="layui-btn layui-btn-normal" >重置</button>
                    </div>
                </form>
                <!--顶部按钮展示区域 【 tpl-button 】 -->
                <div class="group-button tpl-button" id="toolbar"></div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table" class="table text-nowrap"></table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>

</body>


<div th:include="public/public_js::public_js"></div>
<div th:include="public/public_btn::public_btn"></div>
<script th:inline="javascript">
    $(function () {
        $(".moreBtn").on("click",function () {
            $(".moreSearch").toggle();
        })
    });
    var functions = [[${functions}]];
    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate', 'tablebutton'], function () {

        var zzpUtils= layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate,
            tablebtn = layui.tablebutton;
        tablebtn.buildOnClick({
            type: 1,
            temp: $("#function_tpl"),
            functions: functions.headBtn,
            row: null,
            event: {
                searchEvent: function(){
                    zzpUtils.refreshTable("#table");
                },
                /*编辑*/
                editEvent: function (data) {
                    if (data.row != undefined) {
                        upDialog(data);
                    }
                },
                /*打印*/
                printEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        printDialog(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            printDialog(arr);
                        }else{
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                /*创建装车单*/
                createEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        createDialog(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            createDialog(arr);
                        }else{
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                /*协助称重*/
                assistEvent: function (data) {
                    assistDialog(data.row.id);
                },
                /*下发PDA任务*/
                generateEvent: function (data) {
                    generateDialog(data);
                },
                /*删除*/
                deleteEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        delDialog(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            delDialog(arr);
                        }else{
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                /*发运*/
                forwardingEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        forwardingDialog(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            forwardingDialog(arr);
                        }else{
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                //附件管理
                accessoryEvent: function (data) {
                        upload();
                },
            }
        });
        //初始化
        zzpUtils.webSocket.init();
        //修改承运商信息
        function upDialog(data) {
            var id=data.row.id;
            var bz=data.row.bz;
            var fhfs=data.row.fhfs;
            var kddh=data.row.kddh;
            var sjzl=data.row.sjzl;
            var yf=data.row.yf;
                zzpUtils.dialog({
                    title: "修改承运商信息",
                    type: 2,
                    content: "/assistDelivery/edit?id=" + id+"&bz="+bz+"&fhfs="+fhfs+"&kddh="+kddh+"&sjzl="+sjzl+"&yf="+yf,
                    area: ['80%', '80%'], //设置dialog大小，也可以不设置，
                    end: function () {//修改成功后刷新
                        zzpUtils.refreshTable("#table");
                    }
                });
        }

        //删除
        function delDialog(ids) {
            zzpUtils.confirm("您将删除选择的数据", function (index) {
                zzpUtils.action({
                    url: "/wmsassistdelivery/del",
                    data: JSON.stringify({ids: ids}),
                    success: function (data) {
                        if(data.message!=""){
                            layer.msg(data.message);
                        }else{
                            layer.msg(data.title);
                        }
                        zzpUtils.refreshTable("#table");
                    }
                })
            })
            return false;
        }
        //附件上传
        function upload() {
            zzpUtils.dialog({
                title: "附件管理",
                type: 2,
                content: "/assistDelivery/getUpload",
                area: ['80%', '80%'], //设置dialog大小，也可以不设置，
                end: function () {//增加成功后刷新
                    //zzpUtils.refreshTable("#table");
                }
            });
        }
        function printDialog(ids) {
                zzpUtils.confirm("您将打印选择的装车单", function (index) {
                    zzpUtils.action({
                        url: "/wmsloading/assistPrintLoading",
                        data: JSON.stringify({ids: ids}),
                        success: function (data) {
                            if (data.title == '打印装车单失败') {
                                layer.msg(data.message);
                            } else {
                                var LODOP = getLodop();
                                for (var i = 0; i < data.rows.length; i++) {
                                    LODOP.ADD_PRINT_TEXT(0,285,300,30,"大连双迪装载单");
                                    LODOP.SET_PRINT_STYLEA(0, 'FontSize', 20);
                                    LODOP.ADD_PRINT_BARCODE(48, 260, 270, 47, "EAN128B", data.rows[i].zcdbh);
                                    LODOP.ADD_PRINT_TEXT(110, 260, 100, 50, "物流单数");
                                    LODOP.ADD_PRINT_TEXT(110, 350, 307, 50, data.rows[i].zxs);
                                    LODOP.ADD_PRINT_TEXT(140, 260, 100, 50, "总单数");
                                    LODOP.ADD_PRINT_TEXT(140, 350, 307, 50, data.rows[i].zds);
                                    LODOP.ADD_PRINT_TEXT(170, 260, 100, 50, "承运商");
                                    LODOP.ADD_PRINT_TEXT(170, 350, 307, 50, data.rows[i].cyrmc);
                                    LODOP.ADD_PRINT_TEXT(200, 260, 100, 50, "承运车辆");
                                    LODOP.ADD_PRINT_TEXT(200, 350, 307, 50, data.rows[i].cycl);
                                    LODOP.ADD_PRINT_TEXT(230, 260, 100, 50, "打印时间");
                                    var oDate = new Date(); //实例一个时间对象；
                                    var time = oDate.getFullYear() + '-' + (oDate.getMonth() + 1) + '-' + oDate.getDate();
                                    LODOP.ADD_PRINT_TEXT(230, 350, 307, 50, time);
                                    var trs = '';
                                    for (var j = 0; j < data.rows[i].wmsLoadingDetailedList.length; j++) {
                                        trs += '<tr>\n' +
                                            '<td width="150px"  style="border: 1px solid #000;height:18px"><b>' + (j + 1) + '</b></td>\n' +
                                            '<td width="220px" style="border: 1px solid #000;height:18px"><b>' + data.rows[i].wmsLoadingDetailedList[j].wlbh + '</b></td>\n' +
                                            '<td width="220px" style="border: 1px solid #000;height:18px"><b>' + data.rows[i].wmsLoadingDetailedList[j].xbh + '</b></td>\n' +
                                            '<td width="260px" style="border: 1px solid #000;height:18px"><b>' + data.rows[i].wmsLoadingDetailedList[j].shr + '</b></td>\n' +
                                            '</tr>';
                                    }
                                    LODOP.ADD_PRINT_TABLE(334, 125, 500, 280, '<table border=0 cellSpacing=0 cellPadding=0  width="100%">\n' +
                                        '                  <tr>\n' +
                                        '                    <td width="150px"  style="border: 1px solid #000;height:18px"><b>序号</b></td>\n' +
                                        '                    <td width="220px" style="border: 1px solid #000;height:18px"><b>物流单号</b></td>\n' +
                                        '                    <td width="220px" style="border: 1px solid #000;height:18px"><b>订单号</b></td>\n' +
                                        '                    <td width="260px" style="border: 1px solid #000;height:18px"><b>收货人</b></td>\n' +
                                        '\n' +
                                        '                  </tr>' + trs + '<tfoot>\n' +
                                        '                  <tr>\n' +
                                        '                  <th colspan="2" style="border: none; height: 50px">双迪代表</th>\n' +
                                        '                  <th colspan="2" style="border: none; height: 50px">承运人</th>\tr' +
                                        '                  </tr>\n' +
                                        '\n' +
                                        '                  <tr>\n' +
                                        '                  <th colspan="2" style="border: none; height: 50px">日期</th>\n' +
                                        '                  <th colspan="2" style="border: none; height: 50px">日期</th>\tr' +
                                        '                  </tr>\n' +
                                        '\n' +
                                        '                  </tfoot></table>');
                                    if (i >= 0) {
                                        LODOP.NewPage();//分页
                                    }
                                }
                                LODOP.PREVIEW();
                            }
                        }
                    })
                })
                return false;
        }
        //创建装车单
        function createDialog(ids) {
            zzpUtils.dialog({
                title: "选择承运人",
                type: 2,
                content: "/assistDelivery/creat?ids="+ids,
                area: ['48%', '40%'], //设置dialog大小，也可以不设置，
                end: function () {//增加成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            });
        }
        //协助称重
        function assistDialog(id) {
            zzpUtils.dialog({
                title: "协助称重",
                type: 2,
                content: "/assistDelivery/assist?ids="+id,
                area: ['55%', '45%'], //设置dialog大小，也可以不设置，
                end: function () {//增加成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            });
        }
        //下发PDA任务
        function generateDialog(data){
            var ids=data.row.id;
            var zzpUtils = layui.zzpUtils,
                $ = layui.jquery,
                laydate = layui.laydate;
            zzpUtils.dialog({
                title: "下发PDA任务",
                type: 2,
                content: "/assistDelivery/createPda?ids=" + ids,
                area: ['35%', '35%'], //设置dialog大小，也可以不设置，
            });
        }
        //发运
        function forwardingDialog(ids) {
                zzpUtils.confirm("您将发运选择的数据", function (index) {
                    zzpUtils.action({
                        url: "/wmsassistdelivery/pcfy",
                        data: JSON.stringify({ids:ids}),
                        success: function (data) {
                                if(data.message!=""){
                                    layer.msg(data.message);
                                }else{
                                    layer.msg(data.title);
                                }
                            zzpUtils.refreshTable("#table");
                        }
                    })
                })
            return false;
        }
        laydate.render({
            elem: '#test5'
            ,theme: '#20a0ff'
        })
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            isOperate: true,
            pagination: true,
            url: '/wmsassistdelivery/list',
            columns: [{
                field: '',
                checkbox: true
            }, {
                field: 'fqbm',
                title: '发起部门'
            },{
                field: 'fqr',
                title: '发起人'
            },{
                field: 'yt',
                title: '用途'
            },{
                field: 'lsh',
                title: '流水号',
            },{
                field: 'ddh',
                title: '订单号'
            },{
                field: 'show_xfzt',
                title: '下发状态'
            },{
                field: 'zcdbh',
                title: '装车单编号'
            },{
                field: 'ddhbfydh',
                title: '等待合并发运单号'
            },{
                field: 'fhfs',
                title: '发货方式'
            },{
                field: 'yfcdf',
                title: '运费承担方'
            },{
                field: 'shrxm',
                title: '收货人姓名'
            },{
                field: 'shrgj',
                title: '收货人国家'
            },{
                field: 'sf',
                title: '省份',
                visible: false
            },{
                field: 'cs',
                title: '城市',
                visible: false
            },{
                field: 'xq',
                title: '县区',
                visible: false
            },{
                field: 'shdz',
                title: '收货地址',
                visible: false
            },{
                field: 'lxdh',
                title: '联系电话',
                visible: false
            },{
                field: 'yf',
                title: '运费',
                visible: false
            },{
                field: 'zfrq',
                title: '支付日期',
                visible: false
            },{
                field: 'kddh',
                title: '快递单号',
                visible: false
            },{
                field: 'cpmc',
                title: '产品名称',
                visible: false
            },{
                field: 'sl',
                title: '数量',
                visible: false
            },{
                field: 'gg',
                title: '规格',
                visible: false
            },{
                field: 'dw',
                title: '单位',
                visible: false
            },{
                field: 'cplb',
                title: '产品类别',
                visible: false
            },{
                field: 'dj',
                title: '单价',
                visible: false
            },{
                field: 'tdwldh',
                title: '特定物流单号',
                visible: false
            },{
                field: 'hh',
                title: '货号',
                visible: false
            },{
                field: 'fhzy',
                title: '发货摘要',
                visible: false
            },{
                field: 'bz',
                title: '备注',
                visible: false
            }],
            queryParams: function () {//查询条件
                return  zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },
            /*定义表格右侧按钮*/
            operateFormatter: operateFormatter

        });
        /*表格右侧按钮*/
        function operateFormatter(value, row, index) {
            var button ='';
            var buttons1='';
            var button2 = '';
            if(row.xfzt==0){
                 button2 = '<a class="tooltip2" id="tooltip' + row.id + '" data-tooltip-content="#tool' + row.id + '">更多</a>'
                + '<div class="tooltip_templates">'
                    + '<span id="tool' + row.id + '">';
            }
            for (var i = 0; i < functions.tableBtn.length; i++) {
                var btn = '<button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="' + functions.tableBtn[i].event + '">'
                    + functions.tableBtn[i].name
                    + '</button>';
                    //更多之内
                    if(row.xfzt==0){
                        if(functions.tableBtn[i].event=='forwardingEvent'||functions.tableBtn[i].event=='generateEvent'){
                            button2 += btn;
                        }
                    }
                    //更多之外
                    if(row.zcdbh==0){
                        if(row.xfzt==0){
                            if(functions.tableBtn[i].event == 'editEvent'){
                                buttons1 += btn;
                            }
                        }
                        if(functions.tableBtn[i].event == 'createEvent'){
                            buttons1 += btn;
                        }
                    }
                if(functions.tableBtn[i].event == 'printEvent'
                    ||functions.tableBtn[i].event == 'assistEvent'){
                    buttons1 += btn;
                }
            }
            button += buttons1;
            button += button2;
            button += '</span>'
                + '</div>';
            return button;
        }
    });
</script>
</html>